package com.acerola.mrpc.serializer;

import com.acerola.mrpc.constant.SerialType;
import com.alibaba.fastjson.JSON;


/**
 * @program: Chatting
 * @description: fastjson2序列化
 * @author: Acerola
 * @create: 2022-12-07 14:31
 **/
public class FastJson2 implements ISerializer{
    //todo fastjson2的序列化和反序列化存在问题,暂时使用fastjson
    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) {
        return JSON.parseObject(bytes, clazz);
    }

    @Override
    public <T> byte[] serialize(T object) {
        //默认为UTF-8
        return JSON.toJSONBytes(object);
    }

    @Override
    public byte getType() {
        return SerialType.FASTJSON2_SERI.getCode();
    }
}
